package unidt.xf.core.mybatis.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 注入公共字段自动填充,任选注入方式即可
 */
@Slf4j
@Component
public class AutoFillMetaObjectHandler implements MetaObjectHandler {

    private static List<String> tableList = new ArrayList<String>();


    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
       // Long userId = SecurityUserUtil.getUserId();
      /*  if (Objects.nonNull(userId)) {
            log.debug("start insert fill ....");
            this.strictInsertFill(metaObject, "createBy", Long.class, userId);
            this.strictUpdateFill(metaObject, "updateBy",Long.class, userId);

        }*/
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
       /*// Long userId = SecurityUserUtil.getUserId();
        if (Objects.nonNull(userId)) {
            log.debug("start update fill ....");
            this.strictUpdateFill(metaObject, "updateBy", Long.class, userId);
        }*/
    }
}
